package com.finchina.myview;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.view.View;

/**
 * 作者：黄赛赛 on 2015/9/21 14:06
 *
 * @version V1.0
 * @Description: ${todo}()
 */
public class MatrixView extends View {

    Paint mPaint;
    Bitmap mBitmap;

    public MatrixView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_news_top);
        BitmapShader bs = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
        Matrix mx = new Matrix();
//        mx.preScale(0.5f, 1);
//        mx.postScale(2.0f, 1);
        mx.preTranslate(100, 200);
        mx.postTranslate(-100,-200);

//        mx.setRotate(45);
        bs.setLocalMatrix(mx);
        mPaint.setShader(bs);
    }

    @Override
    protected void onDraw(Canvas canvas) {
//        super.onDraw(canvas);
        canvas.drawRect(0,0,getWidth(),getHeight(),mPaint);
    }
}
